<?php
namespace App\Http\Controllers;

use App\Entity\Account\User as UserEntity;
use App\Service\Account\UserService;

use Illuminate\Support\Facades\DB;

/**
 * @Controller
 * @RequestMapping('/user')
 * @ResponseJson
 */
class UserController {

  /** @Autowired */
  private UserService $userService;

  /**
   * 用户列表
   * @Get('/list')
   */
  public function list() {
    return $this->userService->list(null);
  }

  /**
   * @RequestMapping('/get/{uid}', Get, Post)
   */
  public function getUser(/** @Required */ $uid) {
    var_dump($this->userService->listByIds([1,13, 2], array('uId'=>'desc')));
    var_dump($this->userService->page(null, 1, 2), array('uId'=>'desc'));
    echo $this->userService->count();
    $user = $this->userService->getUser($uid);

    // echo $this->userService->updateBatchByIds(array($user));
    return $user;
  }

  /**
   * @Get('/save')
   * @Validation(\App\Consts\ValidationGroup::CREATE)
   */
  public function saveUser(UserEntity $user): int {
    $uid = \Cyberzone\Account\SDK\Account::getLoginUserId();
    $user2 = clone $user;
    $user2->name = $user->name . '2';
    var_dump(\Cyberzone\Account\SDK\Account::register());
    // return 1;
    return $this->userService->saveBatch1([$user, $user2]);
  }

  public function create(UserEntity $user) {

  }
}
